import { Request } from "../node_modules/utils-lib-js/dist/esm/index.js";
const request = new Request("https://api.openai.com");
const __apiKey = "sk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
export const __gptConf = {
  // max_tokens: 2048,// 回复大小限制
  model: "gpt-3.5-turbo", // 语言模型
  temperature: 0.9, // 随机回答，问题相同的前提下，值越高越随机
}; // 默认配置

const messages = [];// 消息列表，关联上下文
// 发送消息
export async function sendMsg(prompt, conf = __gptConf, apiKey = __apiKey) {
  addMessages(messages, prompt);
  return request.POST(
    "/v1/chat/completions",
    {},
    { messages, ...conf },
    {
      headers: {
        "content-type": "application/json",
        Authorization: `Bearer ${apiKey}`,
      },
    }
  );
}

export const addMessages = (msgs, content, role = "user") => {
  msgs.push({ role, content });
  return msgs;
};
